#pragma once
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <string>
#include <clocale>
#include <vector>
#include "vehicle.h"



using namespace std;

class vehicle_register
{

private:
	vector <vehicle> v;

public:
	vehicle_register()
	{
	}

	void add(vehicle b)
	{
		v.push_back(b);
	}
	string list(){
		ostringstream oss;

		for (int i = 0; i < v.size(); i++ ){
			oss << i << ".  " << v[i] << endl;
		}
		return oss.str();
	}
	void del(int i){

		v.erase(v.begin() + i);

	}
	
	void deleta(){

		int d=0;
		cout << list() << endl;
		cout << "ange en post att ta bort" << endl;
		cin >> d;
		del(d);
		cout << list() << endl;

	}

	void WriteToFile(){
		ofstream fout;
		fout.open("Text.txt");

		for (int i = 0; i < v.size(); i++)
		{
			fout << v[i] << endl;

		}

	}
	//filformat (year,brand,purchaseprice,sellingprice) endl;
				
	void ReadFromFile(string o){
		string str, strRow;
		ifstream fin;
		fin.open(o);
		v.clear();
		while (getline(fin, strRow)){
			istringstream iss(strRow);
			

			vehicle a;
			iss >> a;
			if (a.GetYear() != -1){
				v.push_back(a);
			}


		
		}

		fin.close();
		
		}
	void ReadFromFile(){

		ReadFromFile("Text,txt");

	}

	void CalculateStorageValue(){

		double value=0;

		for (int i = 0; i < v.size(); i++){
			value+=v[i].GetSellingprice();	
		}
		 
		cout << value << endl;

		}
		

	~vehicle_register()
	{
	}
};

